package com.example.youxuehu.initializing;

import com.example.youxuehu.bean.Youxuehu;
import org.omg.PortableServer.ThreadPolicy;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.BitSet;
import java.util.concurrent.*;

@Component
public class YouxuehuBean implements InitializingBean {
    @Autowired
    private Youxuehu youxuehu;

    private static ThreadPoolExecutor pool = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
            60L, TimeUnit.SECONDS,
            new SynchronousQueue<Runnable>());

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println(youxuehu);
        BitSet bitSet = new BitSet();
        bitSet.set(1);
        bitSet.set(1);
        bitSet.set(1);
        System.out.println("bitSet size = " + bitSet.size());
        for (int i = 0; i < bitSet.size(); i++) {
            boolean b = bitSet.get(i);
            System.out.println(b);
        }

        pool.execute(new Runnable() {
            @Override
            public void run() {
                System.out.println("执行线程池。。。。");
            }
        });


        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(2);
        scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                System.out.println("run "+ System.currentTimeMillis());
            }
        }, 0, 10000, TimeUnit.MILLISECONDS);
    }
}
